package lsl.leetCode.year2023.test0204_Bisection;

/**
 * 278. 第一个错误的版本
 *
 * @author Zed
 * @description
 * @date 2023/2/4 17:25
 */
public class test278 {
    public static void main(String[] args) {
        System.out.println(firstBadVersion(3));
    }

    //二分法
    public static int firstBadVersion(int n) {
        int left = 1;
        int right = n;
        while (left < right) {
            int mid = left + (right - left) / 2;
            if (isBadVersion(mid)) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        return left;
    }

    public static boolean isBadVersion(int num) {
        return num >= 2;
    }
}
